package com.ribbon.lcn.servicea.service.impl;

import com.codingapi.txlcn.tc.annotation.LcnTransaction;
import com.ribbon.lcn.servicea.client.AccountServiceClient;
import com.ribbon.lcn.servicea.repository.StorageRepository;
import com.ribbon.lcn.servicea.service.BusinessService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author: Ribbon
 * @Date 2019/3/21 14:17
 **/
@Transactional
@Service
@Slf4j
public class BusinessServiceImpl implements BusinessService {
    @Autowired
    private AccountServiceClient accountServiceClient;


    @Autowired
    private StorageRepository storageRepository;
    /**
     * purchase   本地 库存  serviceB 订单  serviceC 金额
     */
    @Override
    @LcnTransaction
    public void purchase(String userId, String commodityCode, int orderCount) {
        //扣金额
        Integer success = accountServiceClient.debit(userId,100);
        //扣库存 --------本地
        storageRepository.calculate(commodityCode,orderCount);
        throw new RuntimeException("cweshi");
    }
}
